import {useRef} from 'react'
import * as THREE from 'three'
import Zjl from '../ping.module.css'
let App=({intersectsRef,canvasRef,lastTouchY})=>{
    let isDragging = useRef(false);
        //鼠标按下时
    let handleMouseDownHei=()=>{
        if(intersectsRef.current){
            isDragging.current=true
        }
    }
    
    let handleMouseMoveHei = (event) => {
        const touch = event.touches[0];
        let jiz=touch.clientY-lastTouchY.current
        lastTouchY.current=touch.clientY
        if (isDragging.current && intersectsRef.current) {
            const scaleFactorZ = jiz *0.2;
            // const positionAttribute = intersectsRef.current.geometry.attributes.position;
        
                // 遍历所有顶点
            // for (let i = 0; i < positionAttribute.count; i++) {
            //         // 获取当前顶点坐标
            //     const vertex = new THREE.Vector3();
            //     vertex.fromBufferAttribute(positionAttribute, i);
        
                    // 如果是上面的顶点（y > 0），增加其 y 坐标
                    // if (vertex.z > 0) {
                        intersectsRef.current.scale.z += scaleFactorZ;
                    // } 
                    // if (vertex.x > 0) {
                    //     vertex.x += 0;  // 增长的量
                    // } 
                    // 更新顶点坐标
            //     positionAttribute.setXYZ(i, vertex.x, vertex.y, vertex.z);
            // }
        
            //     // 需要通知几何体更新
            // positionAttribute.needsUpdate = true;
        }
    }
    
        //鼠标抬起时
    let handleMouseUpHei=()=>{
        isDragging.current =false
        canvasRef.current.children[0].removeEventListener('touchstart', handleMouseDownHei);
        canvasRef.current.children[0].removeEventListener('touchmove', handleMouseMoveHei);
        canvasRef.current.children[0].removeEventListener('touchend', handleMouseUpHei);
    }
    let long=()=>{
        canvasRef.current.children[0].addEventListener('touchstart', handleMouseDownHei);
        canvasRef.current.children[0].addEventListener('touchmove', handleMouseMoveHei);
        canvasRef.current.children[0].addEventListener('touchend', handleMouseUpHei);
    }
    return (
        <>
            <h4 onClick={long}  className={`${Zjl.h4}`}>增高</h4>
        </>
    )
}
export default App


